1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Start stop functions for voicemeeter audio callback
use crate::VoicemeeterRemote;

impl VoicemeeterRemote {
    /// Audio callback start.
    pub fn audio_callback_start(&self) -> Result<(), AudioCallbackStartError> {
        let res = unsafe { self.raw.VBVMR_AudioCallbackStart() };
        match res {
            0 => Ok(()),
            -1 => Err(AudioCallbackStartError::NoServer),
            1 => Err(AudioCallbackStartError::NoCallbackRegistered),
            s => Err(AudioCallbackStartError::Unexpected(s)),
        }
    }

    /// Audio callback stop.
    pub fn audio_callback_stop(&self) -> Result<(), AudioCallbackStopError> {
        let res = unsafe { self.raw.VBVMR_AudioCallbackStop() };
        match res {
            0 => Ok(()),
            -1 => Err(AudioCallbackStopError::NoServer),
            1 => Err(AudioCallbackStopError::NoCallbackRegistered),
            s => Err(AudioCallbackStopError::Unexpected(s)),
        }
    }
}

/// Errors that can occur while registering the audio callback.
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum AudioCallbackStartError {
    // TODO: is this correct?
    /// No server.
    #[error("no server")]
    NoServer,
    /// No callback registered.
    #[error("no callback registered")]
    NoCallbackRegistered,
    /// An unknown error code occured.
    #[error("an unexpected error occurred: error code {0}")]
    Unexpected(i32),
}

/// Errors that can occur while unregistering the audio callback.
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum AudioCallbackStopError {
    // TODO: is this correct?
    /// No server.
    #[error("no server")]
    NoServer,
    /// No callback registered.
    #[error("no callback registered")]
    NoCallbackRegistered,
    /// An unknown error code occured.
    #[error("an unexpected error occurred: error code {0}")]
    Unexpected(i32),
}